<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-09-11 08:39:26
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-09-17 17:00:15
 * @FilePath: \23WRX\city\src\pages\components\Right1.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <div ref="right1" style="height: 150px;margin-top: 10px;"></div>
    </div>
</template>
<script>
import { get } from '@/utils/request';
import { DualAxes } from '@antv/g2plot';
import moment from 'moment';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '实时湿度曲线',
            // 存放湿度数据
            humidData: [],
            params:{
                page:1,
                pageSize:100
            },
            dualAxes: null//1.
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    //侦听器 侦听数据
    watch: {
        ed: {
            handler(n, o) {
                //根据设备信息 重新查询数据 重新渲染图表
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getHumidData();
                //根据最新获取的数据
                this.dualAxes.changeData( [this.humidData, this.humidData]);
            },
            //深度侦听
            deep: true
        }
    },
    methods: {
        loadLine() {

            this.dualAxes = new DualAxes(this.$refs.right1, {
                data: [this.humidData, this.humidData],
                xField: 'insert_time',
                yField: ['temperature', 'humidity'],
                geometryOptions: [
                    {
                        geometry: 'line',
                        color: '#5B8FF9',
                    },
                    {
                        geometry: 'line',
                        color: '#5AD8A6',
                    },
                ],
            });

            this.dualAxes.render();
        },
        
        async getHumidData() {
            let res =await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, "11111");
            let humid = [];
            //将后端获取的数据给
            res.data.list.forEach((item, index, arr) => {
                //由于刻度混乱
                arr[0].temperature = 15.4;
                arr[0].humidity = 36;
                //item表示数组每一项
                item.insert_time = moment(item.insert_time).format("HH:mm:ss");
                //每隔十条取一条
                if (index % 10 == 0) {
                    humid.push(arr[index])
                }
            })
            this.humidData = humid;
        }


    },
    async mounted() {
        await this.getHumidData();
        this.loadLine()
    }

}
</script>
<style lang="less" scoped></style>